<%@page import="com.zhuoshi.bean.ManagerRoleBean"%>
<%@page import="com.zhuoshi.dao.ManagerRoleDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
request.setCharacterEncoding("UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String id = request.getParameter("id");
ManagerRoleDao dao = new ManagerRoleDao();
ManagerRoleBean bean = dao.getManagerRoleBean(Integer.parseInt(id));
pageContext.setAttribute("bean", bean);

String action = request.getParameter("action");
if("edit".equals(action)){
	//out.print(action);
	String role_name = request.getParameter("role_name");
	String role_type = request.getParameter("role_type");
	int sys = bean.getSys();
	ManagerRoleBean roleBean = new ManagerRoleBean();
	roleBean.setId(bean.getId());
	roleBean.setRole_name(role_name);
	roleBean.setRole_type(Integer.parseInt(role_type));
	roleBean.setSys(sys);
	int rows = dao.update(roleBean);
	if(rows>0){
		out.print("<script language='javascript'>alert('保存成功');location.href='role_update.jsp?id="+bean.getId()+"'</script>");
	}else{
		out.print("<script language='javascript'>alert('保存失败');</script>");
	}	
}

%>

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="Bookmark" href="http://localhost:8080/favicon.ico">
<link rel="Shortcut Icon" href="http://localhost:8080/favicon.ico">
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="template/H-ui.min.css">
<link rel="stylesheet" type="text/css" href="template/H-ui.admin.css">
<link rel="stylesheet" type="text/css" href="template/iconfont.css">
<link rel="stylesheet" type="text/css" href="template/icheck.css">
<link rel="stylesheet" type="text/css" href="template/skin.css" id="skin">
<link rel="stylesheet" type="text/css" href="template/style.css">


<title>添加角色</title>




<script type="text/javascript">
function test()
	{
		var username = document.getElementById('username').value;
		if(username=="")
		{
			document.form.username.focus();
			return false;
		}
		var password = document.getElementById('password').value;
		if(password=="")
		{
			document.form.password.focus();
			return false;
		}
		var name = document.getElementById('realname').value;
		if(name=="")
		{
			document.form.name.focus();
			return false;
		}
		var sex = document.getElementById('sex').value;
		if(sex=="")
		{
			document.form.sex.focus();
			return false;
		}
		var job = document.getElementById('job').value;
		if(job=="")
		{
			document.form.job.focus();
			return false;
		}
		var tel = document.getElementById('tel').value;
		if(tel=="")
		{
			document.form.tel.focus();
			return false;
		}
		var email = document.getElementById('email').value;
		if(email=="")
		{
			document.form.email.focus();
			return false;
		}
		var area = document.getElementById('area').value;
		if(area=="")
		{
			document.form.area.focus();
			return false;
		}
		var province = document.getElementById('province').value;
		if(province=="")
		{
			document.form.province.focus();
			return false;
		}
		return true;
  }
</script>
<script>
/* var xhr;

function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xhr = new XMLHttpRequest();
	}
}
function checkState(){
	if(xhr.status==200){
		if(xhr.readyState==4){
			document.getElementById("errmsg").innerHTML = xhr.responseText;
		}
	}
}

function checkRepeat(){
	createXMLHttpRequest();
	xhr.onreadystatechange = checkState();
	var username = document.getElementById("username").value;
	xhr.open("get", "uservalid.jsp?username="+username,true);
	xhr.send(null);
} */
</script>
<link rel="stylesheet" href="template/layer.css" id="layui_layer_skinlayercss"><link href="template/WdatePicker.css" rel="stylesheet" type="text/css"></head>

<body>
<article class="page-container">
	<form action="?action=edit" enctype="application/x-www-form-urlencoded" name="form" method="post" class="form form-horizontal" id="form-member-add" onSubmit="return test(this)" novalidate="novalidate">
		
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分类：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select type="text" class="input-text" style="width:350px;" placeholder="" name="role_type" id="role_type">
					<option value="">-------请选择类别-------</option>
					<option value="2" ${bean.role_type==2? "selected":"" }>系统管理</option>	
					<option value="1" ${bean.role_type==1? "selected":"" }>超级管理</option>
				</select>
			</div>
		</div>
		
		
			
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" style="width:350px;" value="${bean.role_name }" placeholder="" id="role_name" name="role_name">
			</div>
		</div>
		
		
		
		
		
		
		
		
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input type="hidden" name="id" value="${bean.id }" />
				<input class="btn btn-primary radius" type="submit" value="  提交  "> 
				<input class="btn btn-danger radius" type="button" value=" 返 回  " id="transmit" />
			</div>
		</div>
		
		

               
	</form>
</article>

<script type="text/javascript" src="template/jquery.min.js"></script> 
<script type="text/javascript" src="template/layer.js"></script>
<script type="text/javascript" src="template/laypage.js"></script> 
<script type="text/javascript" src="template/jquery.icheck.min.js"></script>
<script type="text/javascript" src="template/WdatePicker.js"></script> 
<script type="text/javascript" src="template/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="template/jquery.validate.min.js"></script> 
<script type="text/javascript" src="template/validate-methods.js"></script> 
<script type="text/javascript" src="template/messages_zh.min.js"></script>
<script type="text/javascript" src="template/H-ui.js"></script><a href="javascript:void(0)" class="Hui-iconfont toTop" title="返回顶部" alt="返回顶部" style="display:none"></a> 
<script type="text/javascript" src="template/H-ui.admin.js"></script> 

 <script type="text/javascript">
    $('#transmit').on('click', function(){
        //刷新页面
        parent.window.location.href='rolelist.jsp';
        //获取窗口索引
        var index = parent.layer.getFrameIndex(window.name);
        //关闭弹出层
        parent.layer.close(index);
    });
</script>
 
 
<script type="text/javascript">
	function checkpwd(obj){
	  if(obj.value == "")return false;
	  if(obj.value.match(/[^A-Za-z0-9]/ig)){
	    //alert("密码只能为数字和字母");
	    return false;
	  }
	  return true;
	}
 </script>

<script type="text/javascript">
var xhr;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xhr = new XMLHttpRequest();
	}
	}

	function checkState() {
		if (xhr.status == 200) {
			if (xhr.readyState == 4) {
				//alert("响应");
				document.getElementById("province").innerHTML = xhr.responseText;
			}
		}
	}

	function changeProvince( ){  
      //获取用户选择区域的省份
      createXMLHttpRequest();
	xhr.onreadystatechange = checkState;
	var id = document.getElementById("area").value;
	//alert(id);
	xhr.open("GET", "province.jsp?id="+id,true);
	xhr.send(null);
     
  }  
$(function(){ 
        //文本框失去焦点后 
       $('form :input').blur(function(){ 
            var $parent = $(this).parent(); 
            $parent.find(".formtips").remove(); 
            //验证用户名 
            if( $(this).is('#username') ){ 
               if( this.value==""  ){ 
                     var errorMsg = '用户名不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }else{ 
                    check(this.value);
                   function check(username){
              $.ajax({
            //提交数据的类型 POST GET
            type:"POST",
            //提交的网址
            url:"uservalid.jsp",
            //提交的数据
            data:{username:username},
            //返回数据的格式
            datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
            //在请求之前调用的函数
            //beforeSend:function(){$("#msg").html("logining");},
            //成功返回之后调用的函数       
                
            success:function(data){
            //alert(data);
            if(data.replace(/\s/g,'')=="此用户不存在"){
            	$parent.append('<span class="formtips onSuccess" style="color:green"></span>');
            }else{
           		$parent.append('<span class="formtips onError" style="color:red">'+data+'</span>');
           		}            
            }  ,
            //调用执行后调用的函数
            complete: function(XMLHttpRequest, textStatus){
            },
            //调用出错执行的函数
            error: function(){
                //请求出错处理
            }         
         });}}} 
            
            //用户密码
            if( $(this).is('#role_type') ){ 
               if( this.value==""  ){ 
                     var errorMsg = '分类不能为空'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }else{ 
                      
                     $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               } 
            } 
          	//角色名
            if( $(this).is('#rolename') ){ 
               if( this.value==""  ){ 
                     var errorMsg = '角色名不能为空.'; 
                     $parent.append('<span class="formtips onError" style="color:red">'+errorMsg+'</span>'); 
               }else{ 
                     
                     $parent.append('<span class="formtips onSuccess" style="color:green"></span>'); 
               } 
            } 
          
          	//性别
 
          
          	//职位
 
            	//电话
             
             	//email
 
              	//区域

              	//省份

       }).keyup(function(){ 
          $(this).triggerHandler("blur"); 
       }).focus(function(){ 
            $(this).triggerHandler("blur"); 
       });//end blur 
 
        
       //提交，最终验证。 
       $('#send').click(function(){ 
               $("form :input.required").trigger('blur'); 
               var numError = $('form .onError').length; 
               if(numError!=0){ 
                   return false;   
		  }else{
		  return true;}
               
       
        }); 
})
</script>

<script type="text/javascript">
$(function(){
	
	$("#form-member-add").validate({
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
			//parent.$('.btn-refresh').click();
			
		}
	});
});
</script> 


</body>
</html>